/*
 * Copyright (C) 2010 Ahti Legonkov.
 * 
 * This file is part of Java 1.5 parser and Abstract Syntax Tree.
 *
 * Java 1.5 parser and Abstract Syntax Tree is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * Java 1.5 parser and Abstract Syntax Tree is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with Java 1.5 parser and Abstract Syntax Tree.  If not, see <http://www.gnu.org/licenses/>.
 */
package japa.parser.ast.body;

import japa.parser.ParseException;
import japa.parser.ast.expr.AnnotationExpr;
import japa.parser.ast.expr.NameExpr;
import japa.parser.ast.stmt.BlockStmt;
import japa.parser.ast.visitor.GenericVisitor;
import japa.parser.ast.visitor.VoidVisitor;

import japa.util.Collections;
import java.util.List;

/**
 * @author Ahti Legonkov
 */
public final class DestructorDeclaration extends BodyDeclaration {

    private int modifiers;

    private String name;

    private List<NameExpr> throws_;

    private BlockStmt block;

    public DestructorDeclaration() {
    }

    public DestructorDeclaration(DestructorDeclaration that) {
        super(that);

        this.modifiers = that.modifiers;
        this.name = that.name;
        this.throws_ = Collections.clone(that.throws_);
        if (that.block != null)
            this.block = that.block.clone();
    }

    public DestructorDeclaration(int modifiers, String name) throws ParseException
    {
        this.modifiers = modifiers;
        this.name = name;
    }

    public DestructorDeclaration(
            JavadocComment javaDoc, int modifiers,
            List<AnnotationExpr> annotations, String name,
            List<NameExpr> throws_, BlockStmt block) throws ParseException
    {
        super(annotations, javaDoc);
        this.modifiers = modifiers;
        this.name = name;
        this.throws_ = throws_;
        this.block = block;
    }

    public DestructorDeclaration(
            int beginLine, int beginColumn, int endLine, int endColumn,
            JavadocComment javaDoc, int modifiers, 
            List<AnnotationExpr> annotations, String name,
            List<NameExpr> throws_, BlockStmt block) throws ParseException
    {
        super(beginLine, beginColumn, endLine, endColumn, annotations, javaDoc);
        this.modifiers = modifiers;
        this.name = name;
        this.throws_ = throws_;
        this.block = block;
    }

    @Override
    public <R, A> R accept(GenericVisitor<R, A> v, A arg)
    {
        return v.visit(this, arg);
    }

    @Override
    public <A> void accept(VoidVisitor<A> v, A arg)
    {
        v.visit(this, arg);
    }

    public BlockStmt getBlock()
    {
        return block;
    }

    /**
     * Return the modifiers of this member declaration.
     * 
     * @see ModifierSet
     * @return modifiers
     */
    public int getModifiers()
    {
        return modifiers;
    }

    public String getName()
    {
        return name;
    }

    public List<NameExpr> getThrows() {
        return throws_;
    }

    public void setBlock(BlockStmt block) {
        this.block = block;
    }

    public void setModifiers(int modifiers) {
        this.modifiers = modifiers;
    }

    public void setName(String name) {
        this.name = name;
    }

    public void setThrows(List<NameExpr> throws_) {
        this.throws_ = throws_;
    }

    @Override
    public DestructorDeclaration clone() {
        return new DestructorDeclaration(this);
    }
}
